<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户退货申请管理</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/metro-blue/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/icon.css">
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var url;

        function searchReturnApply() {
            $("#dg").datagrid('load', {
                "saleListNumber": $("#s_saleNumber").val(),
                "customerId": $("#s_customer").val(),
                "bSaleDate": $("#s_bSaleDate").val(),
                "eSaleDate": $("#s_eSaleDate").val(),
                "status": $("#s_status").val()
            });
        }

        function resetValue() {

            $("#name").val("");
            $("#remarks").val("");
        }

        function closeReturnApplyDialog() {
            $("#dlg").dialog("close");
            resetValue();
        }

        function saveReturnApply() {
            $("#fm").form("submit", {
                url: url,
                onSubmit: function () {
                    return $(this).form("validate");
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        $.messager.alert("系统提示", "保存成功！");
                        resetValue();
                        $("#dlg").dialog("close");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", "保存失败!");
                    }
                }
            });
        }

        function openReturnApplyAddDialog() {
            $("#dlg").dialog("open").dialog("setTitle", "添加客户订单信息");
            url = "/admin/saleList/save";
        }

        function openReturnApplyModifyDialog() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一条要修改的数据！");
                return;
            }
            var row = selectedRows[0];
            $("#dlg").dialog("open").dialog("setTitle", "修改客户订单信息");
            $("#fm").form("load", row);
            url = "/admin/saleList/save?id=" + row.id;
        }

        function deleteReturnApply() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据！");
                return;
            }
            var strIds = [];
            for (var i = 0; i < selectedRows.length; i++) {
                strIds.push(selectedRows[i].id);
            }
            var ids = strIds.join(",");
            $.messager.confirm("系统提示", "您确定要删除这<span style='color: red'>" + selectedRows.length + "</span>条数据吗?", function (r) {
                if (r) {
                    $.post("/admin/saleList/delete", {ids: ids}, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "数据已成功删除！");
                            $("#dg").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }

        function formatCustomerContact(val, row) {
            return val.contact;
        }

        function formatCustomerUserName(val, row) {
            return row.customer.userName;
        }

        function formatState(val, row) {
            if (val == 1) {
                return "<span style='color: blue'>已支付</span>";
            } else if (val == 2) {
                return "<span style='color: red'>未支付</span>";
            } else if (val == 3) {
                return "<span style='color: #e0a800'>已发货</span>";
            } else if (val == 4) {
                return "<span style='color: hotpink'>派送中</span>";
            } else if (val == 5) {
                return "<span style='color: #0c9c6e'>已收货</span>";
            } else if (val == 6) {
                return "<span style='color: rebeccapurple'>订单已取消</span>";
            }
        }

        function handleReturnApply(status) {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一个要处理的销售单！");
                return;
            }
            var id = selectedRows[0].id;
            if (status == 0) {
                var str = "未处理";
            } else if (status == 1) {
                var str = "同意退货";
            } else if (status == 2) {
                var str = "不同意退货";
            }
            $.messager.confirm("系统提示", "确认要给这个退货申请进行<span style='color: red'>" + str + "</span>操作吗?", function (r) {
                if (r) {
                    $.post("/admin/returnApply/handleReturnApply", {id: id, status: status}, function (result) {
                        if (result.success) {
                            $("#dg").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    })
                }
            });
        }

        function openReturnApplyDetailDialog() {
            var selectedRows = $("#dg").datagrid('getSelections');
            if (selectedRows.length != 1) {
                $.messager.alert("系统提示", "请选择一条要查看的数据！");
                return;
            }
            var row = selectedRows[0];
            $("#dg2").datagrid('load', {
                "saleListId": row.saleListId
            });
            $("#saleListNumber").val(row.saleListNumber);
            $("#customer").val(row.customer.contact + "(用户名:" + row.customer.userName + ")");
            var v = row.status;
            if (v == 0) {
                $("#ReturnApplyStatus").val("未处理");
            } else if (v == 1) {
                $("#ReturnApplyStatus").val("已同意退货");
            } else if (v == 2) {
                $("#ReturnApplyStatus").val("不同意退货");
            }
            $("#dlg").dialog("open").dialog("setTitle", "退货商品");
        }

        function formatGoods(val, row) {
            return "<img width=88 height=88 src='/static/images/goodsImage/" + row.goods.imageName + "'/>";
        }

        function formatStatus(val, row) {
            if (val == 0) {
                return "未处理";
            } else if (val == 1) {
                return "同意退货";
            } else {
                return "不同意退货";
            }
        }

        function formatTotal(val,row) {
            return row.price*row.returnNum;
        }
    </script>
</head>
<body style="margin: 1px">
<table id="dg" title="客户订单处理" class="easyui-datagrid"
       fitColumns="true" pagination="true" rownumbers="true" singleselect="true"
       url="/admin/returnApply/list" fit="true" toolbar="#tb">
    <thead>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="id" width="20" align="center" hidden="true">编号</th>
    <th field="saleListNumber" width="50" align="center">订单号</th>
    <th field="applyDate" width="50" align="center">申请时间</th>
    <th field="customer2" width="40" align="center" formatter="formatCustomerUserName">所属客户用户名</th>
    <th field="customer" width="40" align="center" formatter="formatCustomerContact">所属客户名称</th>
    <th field="num" width="50" align="center">退货数量</th>
    <th field="status" width="50" align="center" formatter="formatStatus">当前状态</th>
    <th field="reason" width="50" align="center">退货理由</th>
    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:openReturnApplyDetailDialog()" class="easyui-linkbutton" plain="false">查看退货申请详情</a>
        <a href="javascript:handleReturnApply(0)" class="easyui-linkbutton" plain="false">未处理</a>
        <a href="javascript:handleReturnApply(1)" class="easyui-linkbutton" plain="false">同意退货</a>
        <a href="javascript:handleReturnApply(2)" class="easyui-linkbutton" plain="false">不同意退货</a>
    </div>
    <div>
        &nbsp;订单号:&nbsp;
        <input type="text" id="s_saleNumber" size="20" style="height: 25px"
               onkeydown="if(event.keyCode==13) searchReturnApply()"/>
        &nbsp;客户用户名:&nbsp;
        <input class="easyui-combobox" id="s_customer" name="customer.id"
               style="width: 180px"
               data-options="panelHeight:'auto',valueField:'id',textField:'userName',url:'/admin/customer/comboList'"/>
        &nbsp;日期:
        <input id="s_bSaleDate" class="easyui-datetimebox" editable=false style="width:180px"/>
        &nbsp;-&nbsp;
        <input id="s_eSaleDate" class="easyui-datetimebox" editable=false style="width:180px"/>
        &nbsp;&nbsp;&nbsp;当前状态:&nbsp;
        <select class="easyui-combobox" id="s_status" style="width: 110px" editable="false" panelHeight="auto">
            <option value="">全部</option>
            <option value="0">未处理</option>
            <option value="1">同意退货</option>
            <option value="2">不同意退货</option>
        </select>
        <a href="javascript:searchReturnApply()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>


<div id="dlg" class="easyui-dialog" style="width: 1200px;height:550px;padding: 5px 30px"
     closed="true" buttons="#dlg-buttons">
    <table cellspacing="8px">
        <tr>
            <td>订单号：</td>
            <td><input type="text" id="saleListNumber" readonly="readonly" style="width: 200px"/></td>
            <td>&nbsp;</td>
            <td>订单人：</td>
            <td><input type="text" id="customer" readonly="readonly" style="width: 200px"/></td>
        </tr>
        <tr>
            <td>订单状态：</td>
            <td><input type="text" id="ReturnApplyStatus" readonly="readonly" style="width: 200px"/></td>
        </tr>
    </table>
    <br/>
    <table id="dg2" title="退货商品列表" class="easyui-datagrid"
           pagination="true" rownumbers="true" pageSize="10" height="55"
           url="/admin/saleListGoods/list" style="height: 400px;width: 1100px">
        <thead>
        <tr>
            <th field="goods" width="100" align="center" formatter="formatGoods">商品图片</th>
            <th field="name" width="650" align="center">商品名称</th>
            <th field="price" width="100" align="center">商品价格</th>
            <th field="returnNum" width="100" align="center">商品数量</th>
            <th field="total" width="100" align="center" formatter="formatTotal">小计(单位:元)</th>
        </tr>
        </thead>
    </table>
</div>

<div id="dlg-buttons">
    <a href="javascript:closeReturnApplyDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>